﻿@{
    @using YiSha.Entity.Business;
    @using YiSha.Util.Extension;
    @using YiSha.Enum;
    @using YiSha.Enum.OrganizationManage; Layout = "~/Views/Shared/_FormWhite.cshtml"; }
    <style>

        table {
            border-collapse: collapse;
            border: 1px solid #000000;
        }

        .row {
            height: 60px;
        }

        td {
            border-collapse: collapse;
            border: 1px solid #000000;
            height: 30px;
            margin-left: 10px;
        }

        input {
            border: none;
            border-bottom: #8D8D8D 1px solid;
            box-shadow: 0px 0px 0px 0px;
        }

        .noneinput {
            border: none;
            border-bottom: #8D8D8D 0px solid;
            box-shadow: 0px 0px 0px 0px;
        }

        .divtitle {
            float: left;
            vertical-align: middle;
            text-align: center;
            line-height: 30px;
            padding-left: 10px
        }
    </style>
<div class="wrapper animated fadeInRight">
    <form id="form" class="form-horizontal m">
        <input type="hidden" id="pId" />
        <input type="hidden" id="prescriptionId" col="PrescriptionId" />
        <input type="hidden" id="personId" col="PersonId" />
        <input type="hidden" id="followUpSort" col="FollowUpSort" />
        
        <table width="100%">
            <tr class="row">
                <td style="border:0px">姓名：<span id="realName"></span></td>
                <td style="border: 0px">性别：<span id="genderText"></span></td>
                <td style="border: 0px">年龄：<span id="age"></span></td>

                <td style="border: 0px" colspan="2">建档时间：<span id="createTime"></span></td>
                <td style="border:0px">档案编号：<span id="personNum"></span></td>
            </tr>
            <tr class="row">

                <td style="border: 0px" colspan="3">随访日期：<input id="thisDate" col="ThisDate" type="text" placeholder="yyyy-MM-dd" /></td>

                <td style="border: 0px" align="right" colspan="3">下次随访日期：<input id="nextFollowUpTime" col="NextFollowUpTime" type="text" placeholder="yyyy-MM-dd" /></td>

            </tr>
            <tr class="row">
                <td colspan="6" style="border: 0px">
                    <div style="float:left;width:50%">
                        <table width="100%">
                            <tr class="row">
                                <td rowspan="5" align="center">
                                    左眼
                                </td>
                                <td>
                                    调理前：<input id="eyeLeftBefore" col="EyeLeftBefore" type="text" />
                                </td>
                            </tr>
                            <tr class="row">
                                <td>
                                    调理后：<input id="eyeLeftAfter" col="EyeLeftAfter" type="text" />
                                </td>
                            </tr>
                            <tr class="row">
                                <td>
                                    当日增幅：<input id="eyeLeftDayGrowthRate" col="EyeLeftDayGrowthRate" type="text" />
                                </td>
                            </tr>
                            <tr class="row">
                                <td>
                                    总增幅：<input id="eyeLeftAllGrowthRate" col="EyeLeftAllGrowthRate" type="text" />
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div style="float:right;width:50%">
                        <table width="100%">
                            <tr class="row">
                                <td rowspan="5" style="border-left:0px" align="center">
                                    右眼
                                </td>
                                <td>
                                    调理前：<input id="eyeRightBefore" col="EyeRightBefore" type="text" />
                                </td>
                            </tr>
                            <tr class="row">
                                <td>
                                    调理后：<input id="eyeRightAfter" col="EyeRightAfter" type="text" />
                                </td>
                            </tr>
                            <tr class="row">
                                <td>
                                    当日增幅：<input id="eyeRightDayGrowthRate" col="EyeRightDayGrowthRate" type="text" />
                                </td>
                            </tr>
                            <tr class="row">
                                <td>
                                    总增幅：<input id="eyeRightAllGrowthRate" col="EyeRightAllGrowthRate" type="text" />
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>

<script type="text/javascript">
    var id = ys.request("id");
    var prescriptionId = ys.request("prescriptionId");
    $("#pId").val(prescriptionId);
    $(function () {


        laydate.render({
            elem: '#thisDate',
            max: $("#nextFollowUpTime").val(),
            theme: 'molv',
            trigger: 'click',
            done: function (value, date) {
                // 结束时间大于开始时间
                if (value !== '') {
                    endDate.config.min.year = date.year;
                    endDate.config.min.month = date.month - 1;
                    endDate.config.min.date = date.date;
                } else {
                    endDate.config.min.year = '';
                    endDate.config.min.month = '';
                    endDate.config.min.date = '';
                }
            }
        });

        laydate.render({
            elem: '#nextFollowUpTime',
            min: $('#thisDate').val(),
            theme: 'molv',
            trigger: 'click',
            done: function (value, date) {
                // 开始时间小于结束时间
                if (value !== '') {
                    startDate.config.max.year = date.year;
                    startDate.config.max.month = date.month - 1;
                    startDate.config.max.date = date.date;
                } else {
                    startDate.config.max.year = '';
                    startDate.config.max.month = '';
                    startDate.config.max.date = '';
                }
            }

        });

        getForm();

        $("#form").validate({
            rules: {
                personName: { required: true }
            }
        });
    });

    function getForm() {

        if (id > 0) {

            ys.ajax({
                url: '@Url.Content("~/eyeFollowUp/GetFormJson")' + '?id=' + id,
                type: "get",
                success: function (obj) {
                    if (obj.Tag == 1) {
                        var result = obj.Data;

                        console.log(result);
                        $("#form").setWebControls(result);
                        $("#prescriptionId").val(result.PrescriptionIdStr);
                        $("#createTime").html(ys.formatDate(result.BaseCreateTime, "yyyy-MM-dd"));
                        $("#personId").val(result.PersonIdStr);
                        $("#personNum").html(result.PersonIdStr);
                            $("#realName").html(result.RealName);
                            $("#age").html(result.Age);
                        $("#genderText").html(result.GenderText);
                        $("#thisDate").val(ys.formatDate(result.ThisDate, "yyyy-MM-dd"));
                        $("#nextFollowUpTime").val(ys.formatDate(result.NextFollowUpTime, "yyyy-MM-dd"));
                    }
                }
            });
        }
        else {
            if (prescriptionId != null) {

                ys.ajax({
                    url: '@Url.Content("~/person/GetprescriptionFormJsonFormJson")' + '?id=' + prescriptionId,
                    type: "get",
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            var result = obj.Data;
                            console.log(result)

                            $("#form").setWebControls(result);
                            $("#createTime").html(result.BaseCreateTime);
                            $("#personId").val(result.Id);
                            $("#personNum").html(result.Id);
                            $("#prescriptionId").val(prescriptionId);
                            $("#realName").html(result.RealName);
                            $("#age").html(result.Age);
                            $("#genderText").html(result.GenderText);
                            $("#thisDate").val('@ViewBag.ThisDate');
                            $("#nextFollowUpTime").val('@ViewBag.NextFollowUpTime');


                        }
                    }
                });
            }
        }
    }

    function saveForm(index) {
       
        if ($("#form").validate().form()) {

            var postData = $("#form").getWebControls({ Id: id });


            ys.ajax({
                url: '@Url.Content("~/eyeFollowUp/SaveFormJson")',
                type: "post",
                data: postData,
                success: function (obj) {
                    if (obj.Tag == 1) {
                        ys.msgSuccess(obj.Message);
                        parent.searchGrid();
                        parent.layer.close(index);
                    }
                    else {
                        ys.msgError(obj.Message);
                    }
                }
            });
        }
    }

</script>
